package com.juyu.miliao.api.controller;

import javax.annotation.Resource;

import com.juyu.miliao.api.constant.EmailProperties;
//import com.juyu.miliao.api.util.EmailSend;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.juyu.miliao.api.domain.Opinion;
import com.juyu.miliao.api.service.OpinionService;
import com.juyu.miliao.api.validator.OpinionCheck;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.exception.IllegalParamException;

/**
 * 意见建议
 * 
 * @author wbf
 */
@RestController
@RequestMapping("/opinion")
public class OpinionController {

	@Resource
	OpinionService opinionService;
	@Resource
	EmailProperties eps;

	@PostMapping()
	public void insertOpinion(Authentication token, @Validated(OpinionCheck.class) Opinion entity) {
		Subject subject = (Subject) token.getPrincipal();
		if (subject.getId() != entity.getUserId())
			throw new IllegalParamException("用户id错误");
		opinionService.insertOpinion(entity);
		//SSL
		eps.setContent(entity.getDes());
		eps.setSubject("蜜聊用户意见反馈");
//		EmailSend.sendEmailBySSl(eps);

	}

}
